package ${package.Controller};
import com.manager.devicemanager.common.Result;
import ${package.Entity}.${entity};
import org.springframework.util.StringUtils;
import ${package.Service}.${table.serviceName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import com.manager.devicemanager.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Tag(name = "${entity}Controller", description = "${table.comment!} 相关接口")
@RestController
@RequestMapping("/${table.entityPath}")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    @Operation(summary = "新增")
    @PostMapping("/save")
    public Result<${entity}> save(@Parameter(description = "${entity} 对象") @RequestBody ${entity} ${entity?uncap_first}){
       ${table.serviceName?uncap_first}.save(${entity?uncap_first});
        return Result.success(${entity?uncap_first});
    }

    @Operation(summary = "按id删除")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@Parameter(description = "记录ID", example = "1") @PathVariable("id") String id){
       ${table.serviceName?uncap_first}.removeById(id);
        return Result.success(id);
    }

    @Operation(summary = "按id修改")
    @PostMapping("/update/{id}")
    public Result<${entity}> update(@Parameter(description = "记录ID", example = "1") @PathVariable("id") String id, @Parameter(description = "${entity} 对象") @RequestBody ${entity} ${entity?uncap_first}){
        ${entity?uncap_first}.setId(id);
       ${table.serviceName?uncap_first}.updateById(${entity?uncap_first});
        return Result.success(${entity?uncap_first});
    }

    @Operation(summary = "按id查询")
    @GetMapping("/get/{id}")
    public Result<${entity}> get(@Parameter(description = "记录ID", example = "1") @PathVariable("id") String id){
        ${entity} ${entity?uncap_first} =${table.serviceName?uncap_first}.getById(id);
        return Result.success(${entity?uncap_first});
    }

    @Operation(summary = "条件查询带分页")
    @PostMapping("/page")
    public Result<IPage<${entity}>> page(@Parameter(description = "查询条件对象") @RequestBody  PageVO<${entity}> ${entity?uncap_first}Query){
        int pageNum = ${entity?uncap_first}Query.getPageNum();
        int pageSize = ${entity?uncap_first}Query.getPageSize();
        ${entity} ${entity?uncap_first} = ${entity?uncap_first}Query.getCondition();
         QueryWrapper<${entity}> wrapper =new QueryWrapper<>(${entity?uncap_first});
        //if (StringUtils.hasText(${entity?uncap_first}.getName())) {
          //  wrapper.like("name", ${entity?uncap_first}.getName());
        //}
        IPage<${entity}> ${entity?uncap_first}List =${table.serviceName?uncap_first}.page(new Page<>(pageNum, pageSize),wrapper );
        return Result.success(${entity?uncap_first}List);
    }

    @Operation(summary = "条件查询")
    @PostMapping("/list")
    public Result<List<${entity}>> list(@Parameter(description = "${entity} 查询条件对象") @RequestBody ${entity} ${entity?uncap_first}){
        List<${entity}> ${entity?uncap_first}List =${table.serviceName?uncap_first}.list(new QueryWrapper<>(${entity?uncap_first}));
        return Result.success(${entity?uncap_first}List);
    }
}
